package com.lucyyun.lcrpccore.registry;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ConcurrentHashSet;
import cn.hutool.cron.CronUtil;
import cn.hutool.cron.task.Task;
import cn.hutool.json.JSONUtil;

import io.etcd.jetcd.*;
import io.etcd.jetcd.kv.GetResponse;
import io.etcd.jetcd.options.GetOption;
import io.etcd.jetcd.options.PutOption;
import io.etcd.jetcd.watch.WatchEvent;

import java.nio.charset.StandardCharsets;
import java.rmi.registry.Registry;
import java.time.Duration;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;

/**
 * Etcd 注册中心
 */
public class EtcdRegistryces {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Client client = Client.builder().endpoints("http://localhost:2379")
                .build();
        KV kvClinet = client.getKVClient();
        ByteSequence key = ByteSequence.from("test_key5".getBytes());
        ByteSequence value = ByteSequence.from("test_value4".getBytes());

        // put the key
        kvClinet.put(key, value).get();
        
        //get
        CompletableFuture<GetResponse> getFuture = kvClinet.get(key);

        GetResponse getResponse = getFuture.get();
        System.out.println(getResponse);
//        kvClinet.delete(key).get();
    }
}
